public class test03 {
    class Solution {
        public String convert(String s, int numRows) {
            if(numRows<2){
                return s;
            }
            List<StringBuilder> rows = new ArrayList<>();
            for(int i = 0;i<numRows;i++){
                rows.add(new StringBuilder());
            }
            int curRow = 0;
            int flag = -1;
            for(char c:s.toCharArray()){
                rows.get(curRow).append(c);
                if(curRow==0 || curRow==numRows-1){
                    flag = -flag;
                }
                curRow += flag;
            }
            StringBuilder res = new StringBuilder();
            for(int i = 0;i<rows.size();i++){
                res.append(rows.get(i));
            }
            return res.toString();
        }
    }
}
